package leetcode.code0228;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import leetcode.IDebug;

public class Solution implements IDebug {

	public List<String> summaryRanges(int[] nums) {
		List<String> ans = new ArrayList<>();
		if (nums == null || nums.length == 0) {
			return ans;
		}
		Integer left = nums[0];
		int last = nums[0];
		StringBuffer sb = new StringBuffer();
		for (int i = 1; i < nums.length; i++) {
			int cur = nums[i];
			if (cur == last + 1) {
				last = cur;
			} else {
				if (last == left) {
					sb.append(left);
					ans.add(sb.toString());
				} else {
					sb.append(left).append("->").append(last);
					ans.add(sb.toString());
				}
				left = cur;
				last = cur;
				sb = new StringBuffer();
			}
		}
		if (last == left) {
			sb.append(left);
			ans.add(sb.toString());
		} else {
			sb.append(left).append("->").append(last);
			ans.add(sb.toString());
		}
		return ans;
	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		double a = 3;
		double b = 1.1;
		a *= b;
		System.out.println(a);

		BigDecimal bda = new BigDecimal(String.valueOf(3));
		BigDecimal bdb = new BigDecimal(String.valueOf(1.1));
		bda = bda.multiply(bdb);
		System.out.println(bda.doubleValue());

		BigDecimal bda1 = new BigDecimal(3);
		BigDecimal bdb1 = new BigDecimal(1.1);
		bda1 = bda1.multiply(bdb1);
		System.out.println(bda1.doubleValue());

		double c = 2;
		double d = 1.1;
		System.out.println(c - d);
		BigDecimal bc1 = new BigDecimal(2);
		BigDecimal bd1 = new BigDecimal(1.1);
		System.out.println(bc1.subtract(bd1));

		BigDecimal bc2 = new BigDecimal(String.valueOf(2));
		BigDecimal bd2 = new BigDecimal(String.valueOf(1.1));
		System.out.println(bc2.subtract(bd2));

	}

}
